--====================================================================== --Update the appropriate number of rows with a UniqueIdentifier to mark them as 'Selected' --======================================================================
--Get a new GUID DECLARE@iduniqueidentifier SET@id=newid()
DECLARE@tmpnvarchar(600)
SET@tmp='UPDATE WorkflowQueue SET SelectionKey = '''+CAST(@idASnvarchar(40))+''' ' SET@tmp=@tmp+'FROM WorkflowQueue wfq ' SET@tmp=@tmp+'WHERE wfq.WorkFlowQueueKey IN (SELECT TOP '+CAST(@itemCountasnvarchar(10))+' WorkFlowQueueKey ' SET@tmp=@tmp+'FROM WorkflowQueue ' SET@tmp=@tmp+'WHERE SelectionKey IS NULL ' SET@tmp=@tmp+'ORDER BY CreatedOn ASC) ' SET@tmp=@tmp+'AND wfq.SelectionKey IS NULL'
--Update the values of up to the top three rows EXEC(@tmp)
--====================================================================== --Select the rows previously marked for execution and return them to the client --======================================================================